#pragma once

#include <macro.hxx>
#include <string>
#include <ctime>

class Task;
class Action
{
public:
	/*****************************************************
	** typedefs
	******************************************************/
	typedef enum{
		NONE = 0,
		REGISTER,
		REFRESH_HPHM,
		REFRESH_CAPTCHA,
		QUERY,
		REFRESH,
		CHOOSE,
		FINISH,
		RETURN_QUERY,
		WATCH,
		DECAPTCHA,
		REFUND
	}ActionType;
	typedef enum{
		ACTION_RESULT_NONE = 0,
		ACTION_RESULT_SUCCEEDED,
		ACTION_RESULT_INVALID_INFO,
		ACTION_RESULT_CAPTCHA_WRONG,
		ACTION_RESULT_GRAP_FAILED,
		ACTION_RESULT_NETWORK_ERROR,
		ACTION_RESULT_SESSION_EXPIRED,
		ACTION_RESULT_SERVER_ERROR,
		ACTION_RESULT_TASK_FROZEN,
		ACTION_RESULT_DECAPTCHA_ERROR,
		ACTION_RESULT_CONN_RESET_SEND,
		ACTION_RESULT_CONN_RESET_RECV,
		ACTION_RESULT_COMPLETED
	}ActionResult;

	Action(Task* owner);
	virtual void Execute(void);

	string Signature(void) const;
	string Getpromptmsg(void) const;

	PROPERTY_GET(ErrorMsg, std::string, Getpromptmsg);
	PROPERTY(MsgLevel, int);
	PROPERTY(Owner, Task*);
	PROPERTY(Type, ActionType);
	PROPERTY(ActionRes, ActionResult);

protected:
	virtual void PreAction(void);
	virtual void AfterAction(void);

	time_t start;

	string errmsg;
};